<?

class WbPassword {

	public static function Generate($iBlocks=2) {

		//validate Input
		if (defined('WB_PW_BLOCKS')) $iBlocks=WB_PW_BLOCKS;
		$iBlocks=(int)$iBlocks;
		if ($iBlocks < 1) $iBlocks=1;

		$sPassword="";

		//Set defaults
		if (defined('WB_PW_DIGITS')) $sDigits=WB_PW_DIGITS;
		else $sDigits='123456789';

		if (defined('WB_PW_CONSONANTS')) $sConsonants=WB_PW_CONSONANTS;
		else $sConsonants = 'bdfghkmnprstvwxzBDFGHKMNPRSTVWXZ';

		if (defined('WB_PW_VOWELS')) $sVowels=WB_PW_VOWELS;
		else $sVowels='aeiouAEIOU';

		if (defined('WB_PW_SEPARATORS')) $sSeparators=WB_PW_SEPARATORS;
		else $sSeparators = '+-';

		//Generate Arrays
		$aDigits = str_split($sDigits, 1);
		$aConsonants = str_split($sConsonants, 1);
		$aVowels = str_split($sVowels, 1);
		$aSeparators = str_split($sSeparators, 1);

		// create PW blocks
		for($i=0; $i<$iBlocks; $i++) {

		$aBlock = array();

			if (rand (0,1) !=0) {
				$aBlock[] = $aConsonants[array_rand($aConsonants)] . strtolower( $aVowels[array_rand($aVowels)]. $aConsonants[array_rand($aConsonants)] . $aVowels[array_rand($aVowels)]);
			} else {
				$aBlock[] = $aVowels[array_rand($aVowels)] . strtolower( $aConsonants[array_rand($aConsonants)]. $aVowels[array_rand($aVowels)] . $aConsonants[array_rand($aConsonants)]);
			}

			$aBlock[] = $aDigits[array_rand($aDigits)];

			//shuffle($aBlock);
			$aBlock[] = $aSeparators[array_rand($aSeparators)];
			$sPassword.= implode('', $aBlock);
		}


		$sPassword=substr($sPassword,0,-1);

		return $sPassword;
	}

	public static function Hash($sPassword) {
	
	return md5($sPassword);
	}


}//class Password
